<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="ww" uri="/struts-tags"%>
<html xmlns="http://www.w3.org/1999/xhtml">
	<%
		String basePath = request.getContextPath();
		request.setAttribute("base",basePath);
	%>
	
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title><ww:if test="state =='update'">编辑订单</ww:if><ww:else>增加订单</ww:else></title>
		<link rel="stylesheet" href="${base}/css/style.css" type="text/css" />
		<script src="${base }/js/jquery/jquery-1.7.1.min.js"
			type="text/javascript"></script>
		<script type="text/javascript"
			src="${base}/js/My97DatePicker/WdatePicker.js"></script>
		<script src="${base }/js/querycombo.js" type="text/javascript"></script>
		<script type="text/javascript" src="${base}/js/validator.js"></script>
		<script language="javascript" src="${base}/js/jquery/jquery.form.js"></script>
		<script type="text/javascript">
		var baseUrl = "${base}";
function getProduct(){
   var val=$("#institution").val();
	if(val==""){
		alert("请您选择体检机构");
		return;
	}
	$("#productId option").remove();
	$("#productId").append("<option value=''>请选择</option>");
	$.getJSON("${base}/order/getJSONOrderInfo.do",{institutionId:val},function(data){
		$.each(data,function(InfoIndex,Info){
			$("#productId").append('<option saleprice="' + Info['salePrice'] + '" value='+Info["productId"]+'>'+Info["productName"]+'</option>');
		});
	});
}
   
function getPrice(){
	var sex=document.getElementsByName("orderInfo.sex");
    var productNames=document.getElementById("productId");
    var selectedOption = productNames.options[productNames.selectedIndex];
    var productName=selectedOption.innerHTML;
	if(productName.indexOf('男') !=-1){
   		sex[0].checked=true;
   	}else if(productName.indexOf('女')!=-1){
   		sex[1].checked=true;
   	}
    var product=$('#productId');
 	if(isNaN(product.val())){
 		$("#salePrice").val("");
 		return;
 	}
	$("#salePrice").val($(selectedOption).attr("saleprice"));
 		
}
function formsubmit(state){
	if(Validator.Validate(document.getElementById("form"),3)){
		var sexStr=$("input[name='orderInfo.sex']:checked").val();
	if(!sexStr){
		alert("请选择性别!");
		return;
	}
	var dealtype=$("input[name='orderInfo.dealType']:checked").val();
	if(!dealtype){
		alert("请选择支付方式!");
		return;		
	}
	var p = document.getElementById("productId");
		if(p.value==""||p.value=="-1"){
			alert("请选择套餐");
			return;
		}
		var pname = p.options[p.selectedIndex].text;
		if(("男" == sexStr && pname.indexOf("女") != -1)||("女" == sexStr && pname.indexOf("男") != -1)){
			alert("所选套餐对应的性别不正确！");
			return;
		}
	$('#state').val(state);
	var options = {
		dataType:'json',
		success:function(data){
			if(data.success=="true"){
				if(data.action=="add"){
					alert("操作成功");
					//window.location="${base}/order/listOrderInfo.do";
				}
			}else{
				alert("操作失败");
			}
			
		}
	}; 
		$('#form').ajaxForm(options).submit();
	}
}
/*$(document).ready(function(){
	if("${state}"!="update"){
		copyOrder();
	}
});*/
</script> 
	</head>
	<body>
		<div id="rollbar">
			<div>
				<div class="tabcontainer">
					<form id="form" name="form" method="post"
						action="${base}/order/SaveModifyOrderInfo.do" >
						<table id="edittable" style="width:90%">
							<tr>
								<td colspan="3" class="column_head">
									<ww:if test="this.order.id==null">增加订单</ww:if>
									<ww:else>编辑订单</ww:else>
								</td>
							</tr>
							<tr>
								<td class="column_name">
									订单来源：
								</td>
								<td class="column_input">
									<ww:if test="orderInfo.orderFrom==null||'电话网站'.indexOf(orderInfo.orderFrom)!=-1">
										<ww:select list="#{'电话':'电话','网站':'网站','员工自购':'员工自购'}"
											cssStyle="width:155px" 
											name="orderInfo.orderFrom" id="orderFrom"></ww:select>
									</ww:if>
									<ww:else>
										<ww:property value="orderInfo.orderFrom" />
										<input type="hidden" value="${orderInfo.orderFrom}" name="orderInfo.orderFrom"  />
									</ww:else>
								</td>
								<td class="column_msg">
									订单来源
								</td>
							</tr>
							<tr>
								<td class="column_name">
									购买人：
								</td>
								<td class="column_input">
									<input type="text" name="orderInfo.buyUser"
										value="<ww:property value='orderInfo.buyUser'/>" size="21"
										dataType="Require" msg="请输入购买人姓名" />
								</td>
								<td class="column_msg">
									<b style="color: red">* </b>请填写准确真实姓名，以便联系客户。
								</td>
							</tr>/Users/liujunshi/Downloads/html/procedure.html
							<tr>
								<td class="column_name">
									体检人：
								</td>
								<td class="column_input">
									<input type="text" name="orderInfo.tijian" id="tijian"
										value="<ww:property value='orderInfo.tijian'/>" size="21"
										dataType="Require" msg="请输入购买人姓名" />
								</td>
								<td class="column_msg">
									<b style="color: red">* </b>
								</td>
							</tr>
							<tr>
								<td class="column_name">
									年龄：
								</td>
								<td class="column_input">
									<input type="text" name="orderInfo.age" id="age"
										value="<ww:property value='orderInfo.age'/>" size="21"
										dataType="Number" msg="请输入数字" />
								</td>
								<td class="column_msg">
									<b style="color: red">* </b>
								</td>
							</tr>
							<tr>
								<td class="column_name">
									联系电话：
								</td>
								<td class="column_input">
									<input type="text" name="orderInfo.phone"
										value="<ww:property value='orderInfo.phone'/>" size="21"  />
								</td>
								<td class="column_msg">
									<b style="color: red"></b>格式：010-64638863
								</td>
							</tr>
							<tr>
								<td class="column_name">
									手机：
								</td>
								<td class="column_input">
									<input type="text" name="orderInfo.mobile"
										value="<ww:property value='orderInfo.mobile'/>" size="21" />
								</td>
								<td class="column_msg">
									<b style="color: red"></b>格式：13691236262
								</td>
							</tr>
							<tr>
								<td class="column_name">
									邮箱：
								</td>
								<td class="column_input">
									<input type="text" name="orderInfo.email"
										value="<ww:property value='orderInfo.email'/>" size="21"
										dataType="Email" require="false" msg="信箱格式不正确" />
								</td>
								<td class="column_msg">
									<b style="color: red">* </b>格式：klmklm@126.com
								</td>
							</tr>
							<tr>
								<td class="column_name">
									身份证号:
								</td>
								<td class="column_input">
									<input type="text" name="orderInfon.idcard" id="idcard"
										value="<ww:property value='orderInfo.idcard'/>" size="21" />
								</td>
								<td class="column_msg">
									&nbsp;
								</td>
							</tr>
							<tr>
								<td class="column_name">
									联系地址：
								</td>
								<td class="column_input">
									<input type="text" name="orderInfo.address"
										value="<ww:property value='orderInfo.address'/>" size="41" />
								</td>
								<td class="column_msg">
									即：收货地址
								</td>
							</tr>
							<tr>
								<td class="column_name">
									邮编：
								</td>
								<td class="column_input">
									<input type="text" name="orderInfo.postcode"
										value="<ww:property value='orderInfo.postcode'/>" size="21"
										require="false" dataType="Custom" regexp="^[1-9]\d{5}$"
										msg="邮政编码不存在" />
								</td>
								<td class="column_msg">
									&nbsp;
								</td>
							</tr>
							<tr>
								<td class="column_name">
									体检机构：
								</td>
								<td class="column_input">
									<ww:select headerKey="-1" headerValue="请选择..."
										list="institutionList" listKey="id" cssStyle="width:200px"
										listValue="name"
										name="orderInfo.institution.id" id="institution"
										onchange="getProduct()"></ww:select>
									<script type="text/javascript">showQueryBox("institution", "getProduct()");</script>
								</td>
								<td class="column_msg">
									<b style="color: red">* </b>体检中心名称
								</td>
							</tr>
							<tr>
								<td class="column_name">
									套餐名称：
								</td>
								<td class="column_input">
									<ww:select headerKey="-1" headerValue="请选择..."
										list="productList" listKey="id" cssStyle="width:200px"
										listValue="name" name="orderInfo.product.id" id="productId"
										onchange="getPrice()"></ww:select>
									<script type="text/javascript">showQueryBox("productId","getPrice()");</script>
								</td>
								<td class="column_msg">
									<b style="color: red">* </b>请先选择体检机构
								</td>
							</tr>
							<tr>
								<td class="column_name">
									性别：
								</td>
								<td class="column_input">
									<ww:radio list="#{'男':'男','女':'女','未知':'未知'}" name="orderInfo.sex" id="sex"></ww:radio>
								</td>
								<td class="column_msg">
									&nbsp;
								</td>
							</tr>
							<tr>
								<td class="column_name">
									报告领取方式：
								</td>
								<td class="column_input">
									<ww:radio list="#{'报告自取':'报告自取','报告统一回':'报告统一回'}" name="orderInfo.reportType"></ww:radio>
								</td>
								<td class="column_msg">
									&nbsp;
								</td>
							</tr>
							<tr>
								<td class="column_name">
									成交价格：
								</td>
								<td class="column_input">
									<input id="salePrice" type="text" name="orderInfo.product.salePrice" size="21" value="<ww:property value='orderInfo.product.salePrice'/>" msg="必须为数字" />
								</td>
								<td class="column_msg">
									&nbsp;
								</td>
							</tr>
							<tr>
								<td class="column_name">
									付款金额：
								</td>
								<td class="column_input">
									<input id="pay" type="text" name="orderInfo.pay" size="21" value="${orderInfo.pay }" msg="必须为数字" />
								</td>
								<td class="column_msg">
									&nbsp;
								</td>
							</tr>
							<tr>
								<td class="column_name">
									录单备注：
								</td>
								<td class="column_input">
									<textarea rows="4" name="orderInfo.comment"   cols="48" ><ww:property value='orderInfo.comment'/></textarea>
								</td>
								<td class="column_msg">
									备注信息：
								</td>
							</tr>
							<tr>
								<td class="column_name">
									快递公司: 
								</td>
								<td class="column_input">
									<ww:select  headerKey="-1" headerValue="请选择..." list="postList" listKey="id" cssStyle="width:155px" listValue="name" name="postOrder.postAgentId" id="post"  ></ww:select>
								</td>
								<td class="column_msg">
									&nbsp;
								</td>
							</tr>
							<tr>
								<td class="column_name">
									运费支付方式: 
								</td>
								<td class="column_input">
									<ww:radio list="#{'0':'免费','1':'自费'}" name="postOrder.postType"></ww:radio>
								</td>
								<td class="column_msg">
									&nbsp;
								</td>
							</tr>
							<tr>
								<td class="column_name">
									代收款金额: 
								</td>
								<td class="column_input">
									<input type="text" id="agentMoney"  name="postOrder.money" value="<ww:if test="postOrder == null">0</ww:if><ww:else><ww:property value='postOrder.money'/></ww:else>" size="10" require="false" datatype="Integer" msg="金额必须为数字"/>
								</td>
								<td class="column_msg">
									<b style="color:red">*</b>
								</td>
							</tr>
							<tr>
								<td class="column_name">
									代收款费用: 
								</td>
								<td class="column_input">
									<input type="text" id="agentPrice" name="postOrder.expense"  value="<ww:if test="postOrder == null">0</ww:if><ww:else><ww:property value='postOrder.expense'/></ww:else>" size="10" require="false" datatype="Integer" msg="金额必须为数字"/>
								</td>
								<td class="column_msg">
									<b style="color:red">*</b>
								</td>
							</tr>
							<tr>
								<td class="column_name">
									发票抬头: 
								</td>
								<td class="column_input">
									<input type="text" name="invoice.invoiceTitle" value="<ww:property value='invoice.invoiceTitle'/>" size="27" />
								</td>
								<td class="column_msg">
									&nbsp;
								</td>
							</tr>
							<tr>
								<td class="column_name">
									发票金额: 
								</td>
								<td class="column_input">
									<input type="text" name="invoice.invoicePrice" value="<ww:if test="invoice.invoicePrice!=null"><ww:property value='invoice.invoicePrice'/></ww:if><ww:else>0</ww:else>" size="27" require="false" dataType="Integer" msg="必须为数字"/>
								</td>
								<td class="column_msg">
									&nbsp;
								</td>
							</tr>
							<tr>
								<td class="column_name">
									发票税点: 
								</td>
								<td class="column_input">
									<input type="text" name="invoice.lirun" value="<ww:if test="invoice.lirun!=null"><ww:property value='invoice.lirun'/></ww:if><ww:else>0</ww:else>" size="27" require="false" dataType="Integer" msg="必须为数字"/>
								</td>
								<td class="column_msg">
									&nbsp;
								</td>
							</tr>
							<tr>
								<td class="column_name">
									交易方式: 
								</td>
								<td class="column_input">
									<ww:radio list="#{'财付通':'财付通','支付宝':'支付宝','网银':'网银','汇款':'汇款','当面交易':'当面交易','货到付款':'货到付款','快递代收':'快递代收','周期结算':'周期结算'}" name="orderInfo.dealType"></ww:radio>
								</td>
								<td class="column_msg">
									&nbsp;
								</td>
							</tr>
							<tr>
						        <td colspan="3" class="column_bottom">  
						        	<ww:if test="state!='update'">
							        	<input name="Submit" type="button" onClick="formsubmit('add')" value="保存"/>
										<!-- <input name="Submit" type="button" onClick="formsubmit('addto')" value="保存并继续添加"/> -->
									</ww:if>
									<ww:else>
										<input name="Submit" type="button" onClick="formsubmit('add')" value="修改"/>
										<input type="hidden" name="orderInfo.id" value="<ww:property value='orderInfo.id'/>"/>
										<input type="hidden" name="postOrder.id" value="<ww:property value='postOrder.id'/>"/>
										<input type="hidden" name="invoice.id" value="<ww:property value='invoice.id'/>"/>
									</ww:else>
									<input type="hidden" name="state" id="state"/>
						     	</td>
						    </tr>

						</table>

					</form>
				</div>

			</div>
		</div>
	</body>
</html>
